package com.example.securingadmin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author caiwl
 * @date 2020/12/8 16:33
 */
@SpringBootApplication
public class SecuringAdminApplication {
    private static final Logger log = LoggerFactory.getLogger(SecuringAdminApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(SecuringAdminApplication.class, args);
    }

    @Bean
    public CommandLineRunner demo(SysUserRepository repository) {
        return (args) -> {
            BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
            repository.save(new SysUser("admin", passwordEncoder.encode("admin")));
            repository.save(new SysUser("guest", passwordEncoder.encode("123456")));

            repository.findAll().forEach(sysUser -> log.info(sysUser.toString()));
        };
    }
}
